home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java Primer Plus
/
Java Primer Plus (Waite Group Proess)(1996).iso
/
chapter10
/
casting.java
< prev
next >
Wrap
Text File
|
1995-12-31
|
1KB
|
51 lines
/* Airline Passenger */
class AirlinePassenger {
/* Passenger ID number (home phone) */
public int id = 5551234;
/* Indicate diet preference */
protected String dietpref = "Chicken";
/* Accessor */
public String whatFood() { return dietpref; }
/* Stow baggage */
public void stowbaggage() {
System.out.println("Passenger:" + id + " Smash into overhead bin");
}
}
/* Frequent Flyer is a type of Airline Passenger */
class FrequentFlyer extends AirlinePassenger {
/* Passenger FrequentFlyer ID number */
public int id = 435;
public int bonusmiles() { /* calc bonus miles */
return 1000; }
/* Stow baggage */
public void stowbaggage() {
System.out.println("Passenger:" + id + " Place into overhead bin");
}
}
class runner {
static public void main (String args[]) {
FrequentFlyer Billy = new FrequentFlyer();
AirlinePassenger William;
William = (AirlinePassenger)Billy;
System.out.println(Billy.id);
System.out.println(William.id);
System.out.println(Billy.whatFood());
System.out.println(William.whatFood());
Billy.stowbaggage();
William.stowbaggage();
}
}